/*
 * @Author: szx
 * @Date: 2022-03-03 14:15:06
 * @LastEditTime: 2022-03-03 14:19:02
 * @Description:
 * @FilePath: \leetcode\100-199\110\110_2.js
 */
var isBalanced = function (root) {
    if (!root) return true;
    const left = maxDepth(root.left);
    const right = maxDepth(root.right);
    if (Math.abs(left - right) > 1) return false;
    return isBalanced(root.right) && isBalanced(root.left);
};
const maxDepth = (root) => {
    if (!root) return 0;
    return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));
};
